import pandas as pd

import numpy as np
from datetime import datetime


def test1():
    """df 中 筛选时间区间 做额外一些判定"""
    dates = pd.date_range('20240101', periods=60, freq='6s')
    df = pd.DataFrame(np.random.randn(60, 4), index=dates, columns=list('abcd'))
    df['ts'] = dates
    s, e = datetime(2024, 1, 1, 0, 1), datetime(2024, 1, 1, 0, 3)

    print(df)

    # 过滤数据 时间区间
    _df = df[(df['ts'] > s) & (df['ts'] < e)]
    # 筛选是否标准的值
    print(_df)
    tmp_df = _df.loc[:, ['a', 'b', 'c']]
    print(tmp_df.agg(lambda x: x.mean()))
    # print(tmp_df.count())
    # print(tmp_df.mean(axis=1))
    df2 = tmp_df.max(axis=1)
    df1 = pd.DataFrame({'ts': range(len(df2)), 'v': df2})
    print(df1)


if __name__ == '__main__':
    test1()
